//页面刷新
function refreash() {

	winheight = $(window).height();
	winwidth = $(window).width();
	$("body").css("height", winheight);
	$("#bodydiv").css("height", winheight);

	$("#top").css("height", winheight / 7);
	$(".topImg").css("width", winheight / 10 - 25);
	$(".topImg").css("height", winheight / 10 - 25);
	$("#content").css("height", winheight - winheight / 10);
	$("#content2").css("height", winheight - winheight / 10);
	$("#contentBlank").css("height", winheight - winheight / 10);
	$("#toolcontent,#toolcontent2").css("height", winheight);
	var componentW = (winwidth - 100) / 5;
	var componentH = componentW / 2;
	// $("#contentBlank").css("width",winwidth/10);
	$("#content").css("width", componentW * 7 + 30);
	// $("#content2").css("width",componentH*2+50);

	$(".component").css("width", componentW);
	$(".component").css("height", componentH);
	$(".component2").css("width", componentH - 5);
	$(".component2").css("height", componentH);
	$(".component3").css("width", componentW);
	$(".component3").css("height", componentH * 2 + 10);
	$(".component4").css("width", componentH - 5);
	$(".component4").css("height", componentH * 3 + 15);

	$(".popeBox").each(function() {

		$.popeWinRefreash({
			id : this.id
		});
	});

	$(".covertext").css("line-height", componentH + "px");
	$(".covertext").css("font-size", componentH / 4 + "px");

	$(".covertext2").css("line-height", componentH / 6 + "px");
	$(".covertext2").css("font-size", componentH / 12 + "px");

	$("#clock").css("width", componentW - 10);
	$("#clock").css("height", componentH * 0.8 - 10);
	$("#content").isotope({
		masonry : {
			columnWidth : componentH + 5
		}
	});
	$("#content").isotope("reloadItems");
	$("#content").isotope("reLayout");

	musicRefreash();
}
// 组件点击处理
function showComponent(id) {

	$("#" + id).effect("puff", null, 500, function() {

		$("#" + id).show();
	});
	$(".popeBox").hide();
	$(".overlay").click();
	if (id == "component5") {
		showWin("comic1", "compents/comic/main.html");
		if ($("#comic1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="comic1_imgTool" title="漫画" src="image/cover/media/white/mh.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component6") {
		showWin("news1", "compents/news/main.html");
		if ($("#news1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="news1_imgTool" title="新闻" src="image/cover/media/white/MB_0018_viewer.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component7") {
		showWin("music1", "compents/music/main.html");
		if ($("#music1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="music1_imgTool" title="音乐" src="image/cover/media/white/MB_0014_iTunes.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component8") {
		showWin("video1", "compents/video/main.html");
		if ($("#video1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="video1_imgTool" title="视频" src="image/cover/media/white/MB_0024_YT2.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component10") {
		showWin("map1", "compents/map/main.html");
		if ($("#map1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="map1_imgTool" title="周边" src="image/cover/navigation/white/MB_0005_POI.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}

	if (id == "component2") {
		showWin("weather1", "compents/weather/main.html");
		if ($("#weather1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="weather1_imgTool" title="天气" src="image/cover/others/white/MB_0005_weather1.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component1") {
		showWin("calendar1", "compents/calendar/main.html");
		if ($("#calendar1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="calendar1_imgTool" title="日历" src="image/cover/communications/white/MB_0000_calendar.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component12") {
		showWin("postal1", "compents/postal/main.html");
		if ($("#postal1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="postal1_imgTool" title="快递查询" src="image/cover/others/white/car.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}

	if (id == "component13") {
		showWin("stock1", "compents/stock/main.html");
		if ($("#stock1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="stock1_imgTool" title="股票" src="image/cover/others/white/stock.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component9") {
		showWin("note1", "compents/note/main.html");
		if ($("#note1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="note1_imgTool" title="便签" src="image/cover/communications/white/MB_0018_note1.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component11") {
		showWin("calculator1", "compents/calculator/main.html");
		if ($("#calculator1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="calculator1_imgTool" title="计算器" src="image/cover/others/white/MB_0006_calculator.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component14") {
		showWin("translate1", "compents/translate/main.html");
		if ($("#translate1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="translate1_imgTool" title="翻译" src="image/cover/others/white/MB_0018_Translate.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component15") {
		showWin("radio1", "compents/radio/main.html");
		if ($("#radio1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="radio1_imgTool" title="电台" src="image/cover/media/white/MB_0010_radio.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component16") {
		showWin("tv1", "compents/tv/main.html");
		if ($("#tv1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="tv1_imgTool" title="电视台" src="image/cover/media/white/MB_0001_TV.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component17") {
		showWin("mtv1", "compents/mtv/main.html");
		if ($("#mtv1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="mtv1_imgTool" title="MTV" src="image/cover/media/white/MB_0024_TV.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component18") {
		showWin("joke1", "compents/joke/main.html");
		if ($("#joke1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="joke1_imgTool" title="笑话大全" src="image/cover/others/white/MB_0000_Llama.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;"  onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);
	}
	if (id == "component4") {
		showWin("book1", "compents/book/main.html");
		if ($("#book1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="book1_imgTool" title="小说" src="image/cover/others/white/MB_0007_book.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component19") {
		showWin("picnews1", "compents/picnews/main.html");
		if ($("#picnews1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="picnews1_imgTool" title="图集" src="image/cover/media/white/MB_0011_macro.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component20") {
		showWin("tvdrama1", "compents/tvdrama/main.html");
		if ($("#tvdrama1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="tvdrama1_imgTool" title="电视剧" src="image/cover/media/white/MB_0012_landskape.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component21") {
		showWin("file1", "compents/film/main.html");
		if ($("#file1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="file1_imgTool" title="电影" src="image/cover/media/white/MB_0007_VideoRecorder.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component22") {
		showWin("cartoon1", "compents/cartoon/main.html");
		if ($("#cartoon1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="cartoon1_imgTool" title="动画片" src="image/cover/media/white/MB_0008_touch.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	if (id == "component23") {
		showWin("resource1", "compents/resource/main.html");
		if ($("#resource1_imgTool").length != 0) {
			return;
		}
		var img = '<img id="resource1_imgTool" title="我的资源" src="image/cover/network/white/MS_0000s_0014_net.png" style="width:60px;height:60px;cursor:pointer;float:left;padding-top:20px;" onclick="showComponent(\'' + id + '\')"/> ';
		$("#toolimgdiv").append(img);

	}
	refreshImgTool();

}
// 刷新快速启动
function refreshImgTool() {
	var len = $("#toolimgdiv").find("img").length;
	var wlen = parseInt((len - 1) / 5) + 1;
	$("#toolimgdiv").css("width", 60 * wlen);
}
// 打开窗口
function showWin(winid, winurl) {

	$.popeWin({
		id : winid,
		width : 0.5,
		height : 0.8,
		className : "transparent_class2",
		closeImg : "image/close.png",
		url : winurl
	});
}

// 初始化日期
function initDate() {
	var myDate = new Date();
	var year = myDate.getFullYear();
	var month = myDate.getMonth() + 1;
	var day = myDate.getDate();
	var week = myDate.getDay();
	var weekstr = "";

	switch (week) {
	case 0:
		weekstr = "日";
		break;
	case 1:
		weekstr = "一";
		break;
	case 2:
		weekstr = "二";
		break;
	case 3:
		weekstr = "三";
		break;
	case 4:
		weekstr = "四";
		break;
	case 5:
		weekstr = "五";
		break;
	case 6:
		weekstr = "六";
		break;
	default:
		break;

	}
	$("#dateweek").html(year + "年" + month + "月" + day + "日&nbsp;&nbsp;&nbsp;&nbsp;星期" + weekstr);
	return year + "年" + month + "月" + day + "日&nbsp;&nbsp;&nbsp;&nbsp;星期" + weekstr;
}
// 主页按钮功能
function showHome() {
	$(".popeBox").hide();
	$(".overlay").click();
}
// 修改窗口大小
function resizeWin(id, width, height, widthpx, heightpx) {
	$.popeWinResize({
		id : id,
		width : width,
		height : height,
		widthpx : widthpx,
		heightpx : heightpx
	});
}
// 漫画处用到的图片轮播
function showOverlay($modal) {
	// $(".overlay").click();
	$("#msgdiv2").overlay({
		effect : 'fade',
		opacity : 0.5,
		zindex : 6000,
		closeOnClick : true,
		onShow : function() {
			$('body').append($modal);
			Galleria.loadTheme('js/galleria.classic.min.js');

			$('#galleria').galleria({
				transition : 'fadeslide',
				transitionSpeed : 500,
				showInfo : false,
				preload : 3,
				extend : function(options) {
					var gallery = this;
					this.bind('image', function(e) {
						$(e.imageTarget).unbind('click').click(function() {
							gallery.toggleFullscreen();
						});
					});
					gallery.attachKeyboard({
						right : this.next,
						left : this.prev

					});
				}
			});
		},
		onHide : function() {
			$modal.remove();
		}
	});

}
// 打开初始遮罩层
function showOL(id, $div, opacity, color) {

	$("#" + id).overlay({
		effect : 'fade',
		opacity : opacity,
		zindex : 9000,
		color : color,
		closeOnClick : true,
		onShow : function() {
			$('body').append($div);

		},
		onHide : function() {
			$div.remove();
		}
	});
}
// 关闭初始遮罩层
function closeOL(id) {
	$(".overlay").click();
}

// 显示工具栏
function showHeadInfo() {
	$("#headInfo").toggle("slide", null, 500);
}
// 锁屏
function lockScreen() {
	var date = initDate();
	var content = '<div class="lockdate">'+date+'</div>';
	content = content + '<div class="locktime"><ul><li id="lockhours"></li><li id="point">:</li><li id="lockmin"></li><li id="point">:</li><li id="locksec"></li></ul></div>';
	content = content + '<div class="locktxt">向上拖拽解锁</div>';
	var divstr = '<div id="lock" class="lockdiv" style="cursor:move;">'+content+'</div>';
	$("body").append(divstr);
	$("#lock").show("blind", null, 1000, null);
	$("#lock").draggable({
		axis : "y",
		stop : function() {
			unlockScreen();
		}
	});
}
// 解锁
function unlockScreen() {
	$("#lock").hide("blind", null, 1000, function() {
		$("#lock").remove();
	});

}

function mousePosition(ev) {
	if (ev.pageX || ev.pageY) {
		return {
			x : ev.pageX,
			y : ev.pageY
		};
	}
	return {
		x : ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y : ev.clientY + document.body.scrollTop - document.body.clientTop
	};
}

function mouseMove(ev) {
	try {
		ev = ev || window.event;
		var mousePos = mousePosition(ev);

		document.getElementByIdx('mouseXPosition').value = mousePos.x;
		document.getElementByIdx('mouseYPosition').value = mousePos.y;
	} catch (e) {

	}

}
// 修改个人信息
function modifyPersonInfo() {
	var showstate = $("#miniWin_personInfoImg").css("display");
	if (showstate == null || showstate == "none") {
		$.popeWinMini({
			id : "personInfoImg",
			width : 350,
			height : 350,
			url : "framepages/personconfig.html"
		});
	} else {
		$.popeWinMiniClose({
			id : "personInfoImg"
		});
	}

}
// 修改个人偏好
function modifyPersonLike() {
	var showstate = $("#miniWin_personLikeImg").css("display");
	if (showstate == null || showstate == "none") {
		$.popeWinMini({
			id : "personLikeImg",
			width : 700,
			height : 460,
			url : "framepages/personlike.html"
		});
	} else {
		$.popeWinMiniClose({
			id : "personLikeImg"
		});
	}

}
// 退出
function closePow() {
	window.location.href = "login.html";
}

// 更改卡片顺序
function changeCardOrder(cardOrder) {
	var str = jQuery.toJSONString(cardOrder);
	$.getJSON("account_saveOrder.do", {
		id : user.id,
		cardOrder : str
	}, function(data) {
		// alert(data);
	});

}
// 获取当前卡片顺序
function getCurCardOrder() {
	var tmp = "{";
	var $e = $(".element");
	for ( var i = 0; i < $e.length; i++) {
		var e = $e[i];
		if (i == $e.length - 1) {
			tmp = tmp + "\"" + e.id + "\":" + $(e).attr("relorder");
		} else {
			tmp = tmp + "\"" + e.id + "\":" + $(e).attr("relorder") + ",";
		}
	}
	tmp = tmp + "}";
	return tmp;

}
// 更改当前卡片顺序
function changeCurCardOrder(cardOrderJson) {
	var $e = $(".element");
	for ( var i = 0; i < $e.length; i++) {
		var e = $e[i];
		$(e).attr("relorder", cardOrderJson[e.id]);
	}

}
// 修改壁纸
function modifyWallpaper(wallpath) {

	$("#bodydiv").css("background-image", wallpath);
}
// 更新头像
function updateHeadImg() {
	$.getJSON("account_getUser.do", null, function(json) {
		user = json;
		if (user.photo != null && user.photo != "") {
			$("#headImg").attr("src", user.photo);
		}
	});

}
// 初始化时钟
function initClock() {

	setInterval(function() {
		// Create a newDate() object and extract the seconds of the current time
		// on the visitor's
		var seconds = new Date().getSeconds();
		// Add a leading zero to seconds value
		$("#sec,#locksec").html((seconds < 10 ? "0" : "") + seconds);
	}, 1000);

	setInterval(function() {
		// Create a newDate() object and extract the minutes of the current time
		// on the visitor's
		var minutes = new Date().getMinutes();
		// Add a leading zero to the minutes value
		$("#min,#lockmin").html((minutes < 10 ? "0" : "") + minutes);
	}, 1000);

	setInterval(function() {
		// Create a newDate() object and extract the hours of the current time
		// on the visitor's
		var hours = new Date().getHours();
		// Add a leading zero to the hours value
		$("#hours,#lockhours").html((hours < 10 ? "0" : "") + hours);
	}, 1000);
}


//背景图加载完成
function pageOK() {
	$("#startloading").hide();
	$("#tmppicdiv").remove();
	closeOL('msgdiv2');
	
}
